import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'dashboard',
        meta: { title: '首页', icon: 'home', noCache: true }
      }]
  }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/work',
    component: Layout,
    name: 'WorkT',
    meta: { title: '', icon: 'worktoday', roles: ['5', '6'] },
    redirect: '/work/today',
    children: [
      {
        path: 'today',
        name: 'WorkToday',
        component: () => import('@/views/work/today'),
        meta: { title: '今日工作', icon: 'worktoday' },
        hidden: true
      }
    ]
  },
  {
    path: '/receive',
    component: Layout,
    name: 'Receive',
    meta: { title: '签收管理', icon: 'receivelist', roles: ['4', '6'] },
    redirect: '/receive/list',
    children: [
      {
        path: 'in',
        name: 'ReceiveIn',
        component: () => import('@/views/receive/in'),
        meta: { title: '进厂签收', icon: 'receivein' }
      }, {
        path: 'list',
        name: 'ReceiveList',
        component: () => import('@/views/receive/list'),
        meta: { title: '签收管理', icon: 'receivelist' }
      },
      {
        path: 'detail',
        name: 'ReceiveDetail',
        component: () => import('@/views/receive/detail'),
        meta: { title: '签收详情', icon: 'receivelist' },
        hidden: true
      }
    ]
  },
  {
    path: '/pack',
    component: Layout,
    name: 'Pack',
    meta: { title: '打捆管理', icon: 'packagelist', roles: ['5', '6'] },
    redirect: '/pack/list',
    children: [
      {
        path: 'pack',
        name: 'PackPack',
        component: () => import('@/views/pack/pack'),
        meta: { title: '我要打捆', icon: 'packagework', roles: ['5'] }
      },
      // {
      //   path: 'work',
      //   name: 'PackWork',
      //   component: () => import('@/views/pack/work'),
      //   meta: { title: '我要打捆-工作服', icon: 'packagework' },
      //   hidden: true
      // },
      // {
      //   path: 'others',
      //   name: 'PackOthers',
      //   component: () => import('@/views/pack/others'),
      //   meta: { title: '我要打捆-其他', icon: 'packagework' },
      //   hidden: true
      // },
      {
        path: 'list',
        name: 'PackList',
        component: () => import('@/views/pack/list'),
        meta: { title: '打捆管理', icon: 'packagelist', roles: ['5', '6'] }
      }
    ]
  },
  {
    path: '/piece',
    component: Layout,
    name: 'Piece',
    meta: { title: '计件管理', icon: 'piecelist', roles: ['5', '6'] },
    redirect: '/piece/list',
    children: [
      {
        path: 'piece',
        name: 'PiecePiece',
        component: () => import('@/views/piece/piece'),
        meta: { title: '我要计件', icon: 'piecework', roles: ['5'] }
      },
      // {
      //   path: 'work',
      //   name: 'PieceWork',
      //   component: () => import('@/views/piece/work'),
      //   meta: { title: '我要计件-工作服', icon: 'piecework' },
      //   hidden: true
      // },
      // {
      //   path: 'others',
      //   name: 'PieceOthers',
      //   component: () => import('@/views/piece/others'),
      //   meta: { title: '我要计件-其他', icon: 'piecework' },
      //   hidden: true
      // },
      {
        path: 'list',
        name: 'PieceList',
        component: () => import('@/views/piece/list'),
        meta: { title: '计件管理', icon: 'piecelist', roles: ['5', '6'] }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    name: 'Order',
    meta: { title: '下单管理', icon: 'orderlist', roles: ['5', '6'] },
    redirect: '/order/list',
    children: [
      {
        path: 'out',
        name: 'OrderOut',
        component: () => import('@/views/order/out'),
        meta: { title: '出厂下单', icon: 'orderout' }
      },
      {
        path: 'list',
        name: 'OrderList',
        component: () => import('@/views/order/list'),
        meta: { title: '下单管理', icon: 'orderlist' }
      },
      {
        path: 'detail',
        name: 'OrderDetail',
        component: () => import('@/views/order/detail'),
        meta: { title: '出厂批次详情' },
        hidden: true
      }
    ]
  },
  {
    path: '/work',
    component: Layout,
    name: 'WorkS',
    meta: { title: '', icon: 'worksum', roles: ['5', '6'] },
    redirect: '/work/sum',
    children: [
      {
        path: 'sum',
        name: 'WorkSum',
        component: () => import('@/views/work/sum'),
        meta: { title: '工作汇总', icon: 'worksum' },
        hidden: true
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    name: 'User',
    meta: { title: '', icon: 'account' },
    redirect: '/user/center',
    children: [
      {
        path: 'center',
        name: 'UserCenter',
        component: () => import('@/views/user/center'),
        meta: { title: '个人中心', icon: 'account' },
        hidden: true
      }
    ]
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

